import { spawn } from 'child_process'
import { app } from 'electron'
import { resolve } from 'path'

export const startClipboardWatcher = (cb: () => void) => {
  let path = app.getAppPath()
  path = resolve(path.replace('app.asar', 'app.asar.unpacked'), 'bin/clipboard-watcher')

  const process = spawn(path)
  process.stdout.on('data', () => {
    // console.log('clipboard-watcher')
    cb()
  })
  process.stderr.on('data', (data) => {
    console.error(`clipboard-watcher error: ${data}`)
  })

  process.on('close', (code) => {
    console.log(`clipboard-watcher exit with code ${code}`)
  })
}
